package com.caiyouxi.system.service.impl;

import com.caiyouxi.common.bean.QueryParams;
import com.caiyouxi.common.bean.ResData;
import com.caiyouxi.common.cache.RedisService;
import com.caiyouxi.common.service.BaseService;
import com.caiyouxi.system.mapper.MessageReceiversMapper;
import com.caiyouxi.system.model.MessageReceiversBean;
import com.caiyouxi.system.service.MessageReceiversService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
@Transactional
public class MessageReceiversServiceImpl extends BaseService implements MessageReceiversService {
    @Autowired
    private MessageReceiversMapper mapper;
    @Autowired
    private RedisService redisService;

    @Override
    public ResData delete_message(MessageReceiversBean bean) {
        return success(mapper.delete_message(bean));
    }

    @Override
    public ResData insert_selective(MessageReceiversBean bean) {
        return success(mapper.insert_selective(bean));
    }

    @Override
    public ResData select_by_primaryKey(MessageReceiversBean bean) {
        return success(mapper.select_by_primaryKey(bean));
    }

    @Override
    public ResData update_selective(MessageReceiversBean bean) {
        return success(mapper.updateByPrimaryKeySelective(bean));
    }

    @Override
    public ResData select_all_message(MessageReceiversBean bean) {
        Integer pageSize = Integer.parseInt(redisService.get("sys.pagesize").toString());//后台获取默认每页多少调数据
        QueryParams pageList = new QueryParams();
        Integer p = bean.getPage_size();                            //查看前台是否给了每页几条数据
        if(p == 0 || p == null){
            p = pageSize;                                           //如果没给数据，则取默认数据
        }
        bean.setPage_size(p);
        pageList.setPage(bean.getPage());
        pageList.setList(mapper.select_all_message(bean));
        pageList.setTotal(mapper.get_count_message(bean));
        return success(pageList);
    }
}
